{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline" style="width: 340px;">
                            <select name="merchant_id" lay-verify="required" lay-search="">
                                <option value="0"></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}" >{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {else/}
                                <option value="{$t.id}" >{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">日期范围</label>
                        <div class="layui-inline" id="test6">
                            <div class="layui-input-inline">
                                <input type="text" autocomplete="off" name="Date[startDate]" id="startDate" class="layui-input" placeholder="开始日期">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="text" autocomplete="off"  name="Date[endDate]" id="endDate" class="layui-input" placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search"
                            lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i
                                class="layui-icon layui-icon-refresh"></i>{:__('Reset')}
                        </button>
                        <button class="layui-btn layui-bg-black iconfont icon-daochu layui-btn-sm" lay-submit id="export" >导出</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"}
<!--js处理区-->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!-- <button type="button" lay-event="add" class="layui-btn {:node('Cost/add')} layui-btn-sm">去缴费</button> -->
        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
    </div>
</script>

<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn  layui-btn-primary layui-btn-xs {:node('SaleReport/detail')}" data-title="查看" lay-event="detail"><i class="layui-icon">&#xe705;</i></a>
    {{# if(d.status != '驳回'){ }}
        <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('SaleReport/rejected')}" data-title="驳回" lay-event="rejected"><i class="layui-icon">&#x1007;</i></a>
    {{# } }}

</script>

<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'opTable','laydate'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        var laydate = layui.laydate;
        var isSelect = false;
        form.render();
        laydate.render({
            elem: '#startDate'
            ,type: 'date',
            trigger: 'click'
        });
        laydate.render({
            elem: '#endDate'
            ,type: 'date',
            trigger: 'click'
        });
        //导出事件
        $('#export').on('click',function () {
            var merchant_id = $('#merchant_id').val() ;
            var startDate = $('#startDate').val() ;
            var endDate = $('#endDate').val() ;
            console.log(startDate);
            console.log(endDate);
            var data = {
                'startDate' :  startDate ,
                'endDate' :  endDate ,
                'export' :  1
            } ;
            var url = "{:url('export')}"+'?startDate='+startDate+ "&endDate=" + endDate + "&export=" + 1;
            window.open(url);
        });
        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                { title: '', type: 'checkbox', fixed: true },
                {
                    title: '店铺', width: 200, field: 'PP'
                },
                {
                    title: '楼层', width: 140, field: 'LC'
                },
                {
                    title: '铺位号', width: 140, field: 'PWH',
                },
                {
                    title: '业态', width: 140, field: 'YT'
                },
                { title: '金额', field: 'money'},
                { title: '上报笔数', field: 'sale_number',},
                {
                    field: 'create_time', title: '上报时间', width: 160,
                },
                {
                    field: 'report_time', title: '交易日期', width: 160,
                },
                {
                    field: 'status', title: '状态', width: 120,
                },
                {
                    field: 'is_auto', title: '是否自动审核', width: 120,
                },
                { templet: '#operationTpl', align: 'center', minWidth: 160, title: '操作' }
            ]],
            //  展开的列配置
            openCols: [
                { field: 'desc', title: '描述信息' }
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "detail") {
                lucky.CreateOpenForm("查看", "{:url('detail')}?id=" + _id);
                return false;
            } else if (layEvent === 'rejected') {
                var urls = "{:url('rejected')}?id=" + _id;
                lucky.FormatData(_id, urls, '确认驳回？');
            }
        });

        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                if (isSelect == false) {
                    layer.msg("请先搜索", { time: 1500 });
                    return false;
                }
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", { time: 1500 });
                    return false;
                }
                lucky.CreateOpenForm("商户后台缴费", "{:url('add')}?id=" + id);
                // lucky.CreateOpenForm("缴费详情","{:url('detail')}?id=" + _id);
                return false;
            } else if (obj.event === "cui") {
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", { time: 1500 });
                    return false;
                }
                console.log(id);
                lucky.CreateOpenForm("催费", "{:url('rushFee')}?id= " + id);
                return false;
            }

        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            isSelect = true;
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}